package com.lw.common.ext

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.hjq.toast.Toaster
import com.kongzue.dialogx.dialogs.PopTip
import com.lw.common.R

/**
 * 启动Activity
 */
fun AppCompatActivity.launch(clazz: Class<*>) {
    startActivity(Intent(this, clazz))
    overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
}

fun Fragment.launch(clazz: Class<*>) {
    startActivity(Intent(context, clazz))
    (context as Activity).overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
}

/**
 * 启动Activity
 */
fun Context.launch(clazz: Class<*>) {
    val intent = Intent(this, clazz)
    intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
    startActivity(intent)
}

/**
 * 启动Activity，携Bundle
 */
fun AppCompatActivity.launch(bundle: Bundle, clazz: Class<*>) {
    val intent = Intent(this, clazz)
    intent.putExtras(bundle)
    startActivity(intent)
    overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
}

fun Fragment.launch(bundle: Bundle, clazz: Class<*>) {
    val intent = Intent(context, clazz)
    intent.putExtras(bundle)
    startActivity(intent)
    (context as Activity).overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
}

/**
 * 传递intent,启动Activity
 */
fun Context.launch(bundle: Bundle, clazz: Class<*>) {
    val intent = Intent(this, clazz)
    intent.putExtras(bundle)
    intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
    startActivity(intent)
}

/**
 * 显示Toast
 */
fun toast(message: CharSequence) {
    Toaster.show(message)
}

//fun toast(message: CharSequence) {
//    PopTip.show(message)
//}
//
///**
// * 显示Toast
// */
//fun toast(message: CharSequence) {
//    PopTip.show(message)
//}

